﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using Datalayer;
using Common;

namespace Portal_KonTum
{
    public partial class Search : System.Web.UI.Page
    {
        string str = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["q"]))
                {
                    str = Request.QueryString["q"];
                    txtSearch.Text = str;
                    BinData(str);
                }
            }
        }
        void BinData(String str)
        {
            List<New> ex = new List<New>();
            try
            {
                IQueryMgr iq = QueryMgr.GetDbInstance();

                ex = iq.News_GetAllNew_search(str);
                GridView1.DataSource = (ex);
                GridView1.DataBind();

            }
            catch (Exception exa)
            {
                Alert.Show(exa.ToString());
            }
            return;
        }
        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            BinData(str);
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;

            GridView1.EditIndex = -1;
            GridView1.SelectedIndex = -1;
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            str = Server.HtmlEncode(txtSearch.Text);
            Response.Redirect(string.Format("Search.aspx?q={0}", str));
            BinData(str);
        }
    }
}